package cn.imu.appdevexperiment2020;

import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.Toast;

import androidx.annotation.Nullable;

import cn.imu.appdevexperiment2020.base.BaseActivity;
import cn.imu.appdevexperiment2020.utils.ActivityUtil;
import cn.imu.appdevexperiment2020.work01.FirstActivity;
import cn.imu.appdevexperiment2020.work02.SecondActivity;
import cn.imu.appdevexperiment2020.work03.FragmentTabActivity;
import cn.imu.appdevexperiment2020.work03.news.NewsActivityMain;
import cn.imu.appdevexperiment2020.work03.qq.QQMainActivity;
import cn.imu.appdevexperiment2020.work04.LoginActivity;
import cn.imu.appdevexperiment2020.work04.RegisterActivity;
import cn.imu.appdevexperiment2020.work05.TraceActivity;

public class MainActivity extends BaseActivity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        ////////////////////////////////////////////////////////////作业1活动跳转
        //显调用intenet
        Button intent1 = findViewById(R.id.xianshiintent);
        intent1.setOnClickListener((view) -> {
            startActivity(new Intent(MainActivity.this, FirstActivity.class));
        });

        //隐式调用活动
        /** manifiest.xml注册
         *         <activity android:name=".FirstActivity">
         *             <intent-filter>
         *                 <action android:name="first" />
         *                 <category android:name="android.intent.category.DEFAULT" />
         *             </intent-filter>
         *         </activity>
         * **/
        Button button2 = findViewById(R.id.yinshiintent);
        button2.setOnClickListener((view) -> {
            startActivity(new Intent("first"));
        });

        //传递数据
        Button button3 = findViewById(R.id.chuandishuju);

        button3.setOnClickListener((view -> {
            //Intent intent3=new Intent(MainActivity.this,FirstActivity.class);
            // intent3.putExtra("name","胡嘉建");
            //intent3.putExtra("age",18);
            //startActivity(intent3);
            Bundle bundle = new Bundle();
            bundle.putString("name", "胡嘉建");
            bundle.putInt("age", 18);
            ActivityUtil.getInstance().goActivityForResult(this, FirstActivity.class, bundle, 1);

        }));

        //最佳跳转活动写法
        Button bestGoActivity = findViewById(R.id.zuijiaxiefa);
        bestGoActivity.setOnClickListener((view -> {

            ActivityUtil.getInstance().goActivity(this, FirstActivity.class);

        }));

        ////////////////////////////////////////////////////////////作业二 UI界面 list等等.....
        //添加监听
        findViewById(R.id.uijiemian).setOnClickListener(view -> {
            ActivityUtil.getInstance().goActivity(this, SecondActivity.class);
        });


        ////////////////////////////////////////////////////////////作业三碎片
        //微信导航界面
        findViewById(R.id.daohang).setOnClickListener(view -> {
            ActivityUtil.getInstance().goActivity(this, FragmentTabActivity.class);

        });
        //新闻标题
        findViewById(R.id.xinwenbiaoti).setOnClickListener(view -> {
            ActivityUtil.getInstance().goActivity(this, NewsActivityMain.class);

        });
        //qq界面
        findViewById(R.id.liaotian).setOnClickListener(view -> {

            ActivityUtil.getInstance().goActivity(this, QQMainActivity.class);

        });


        findViewById(R.id.posttest).setOnClickListener(view -> {

            ActivityUtil.getInstance().goActivity(this, LoginActivity.class);

        });

        findViewById(R.id.zhuce).setOnClickListener(view -> {

            ActivityUtil.getInstance().goActivity(this, RegisterActivity.class);

        });

        //作业5 快递查询

        findViewById(R.id.kuaidi).setOnClickListener((view -> {

            ActivityUtil.getInstance().goActivity(this, TraceActivity.class);

        }));

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        String name = data.getStringExtra("name");
        Toast.makeText(MainActivity.this, "上一个窗口获取的数据是->" + name, Toast.LENGTH_SHORT).show();

    }
}